package com.qaml.mes.device.repository.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.qaml.mes.device.dao.EqpAuxiliaryStuffDO;
import com.qaml.mes.device.dao.mapper.EqpAuxiliaryStuffMapper;
import com.qaml.mes.device.repository.EqpAuxiliaryStuffRepository;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;

/**
 * @ClassName EqpAuxiliaryStuffRepositoryImpl
 * @Description TODO
 * @Author leikai
 * @Date 2024/2/27 0027 9:56
 * @Version 1.0
 */
@Repository
public class EqpAuxiliaryStuffRepositoryImpl implements EqpAuxiliaryStuffRepository {

    @Resource
    private EqpAuxiliaryStuffMapper eqpAuxiliaryStuffMapper;

    /**
     * 根据设备id删除设备附属物品
     *
     * @param id
     */
    @Override
    public void deleteByEqpId(String id) {
        // LambdaQueryWrapper<EqpAuxiliaryStuffDO> deleteQueryWrapper = new LambdaQueryWrapper<>();
        // deleteQueryWrapper.eq(EqpAuxiliaryStuffDO::getIsDeleted, 0);
        // deleteQueryWrapper.eq(EqpAuxiliaryStuffDO::getEqpId, id);
        // eqpAuxiliaryStuffMapper.delete(deleteQueryWrapper);
        eqpAuxiliaryStuffMapper.deletEqpAuxiliaryStuffByEqpId(id);
    }

    @Override
    public void saveBatch(List<EqpAuxiliaryStuffDO> eqpAuxiliaryStuffDOS) {
        eqpAuxiliaryStuffMapper.saveBatch(eqpAuxiliaryStuffDOS);

    }

    /**
     * 根据设备id查询设备附属物品
     *
     * @param id
     * @return
     */
    @Override
    public List<EqpAuxiliaryStuffDO> getByEqpId(String id) {
        LambdaQueryWrapper<EqpAuxiliaryStuffDO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(EqpAuxiliaryStuffDO::getIsDeleted, 0);
        queryWrapper.eq(EqpAuxiliaryStuffDO::getEqpId, id);
        List<EqpAuxiliaryStuffDO> eqpAuxiliaryStuffDOS = eqpAuxiliaryStuffMapper.selectList(queryWrapper);

        if (eqpAuxiliaryStuffDOS == null || eqpAuxiliaryStuffDOS.isEmpty()) {
            return Collections.emptyList();
        }
        return eqpAuxiliaryStuffDOS;
    }

    /**
     * 根据ids批量修改附属设备
     *
     * @param ids
     */
    @Override
    public void updateEqpAuxiliaryStuffByIds(List<String> ids) {
        if (CollectionUtil.isEmpty(ids)) {
            return;
        }
        eqpAuxiliaryStuffMapper.updateEqpAuxiliaryStuffByIds(ids);
    }

    /**
     * 删除附属物品
     *
     * @param id
     */
    @Override
    public void deleteById(String id) {
        LambdaQueryWrapper<EqpAuxiliaryStuffDO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(EqpAuxiliaryStuffDO::getId, id);
        eqpAuxiliaryStuffMapper.delete(queryWrapper);
    }


}